package com.qianli.cashmama.product.facade.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by xuyang on 2017/7/18.
 */
public enum InterestStrategyEnum {
    PAY_ONCE("PAY_ONCE", "One-time repayment"),                                                         // 一次性还本息
    INTEREST_FIRST("INTEREST_FIRST", "Pre-interest"),                                                   // 先息后本
    EQUAL_PRINCIPAL_AND_INTEREST("EQUAL_PRINCIPAL_AND_INTEREST","Equal principal and interest"),        // 等额本息
    EQUAL_PRINCIPAL("EQUAL_PRINCIPAL","equal principal");                                               // 等额本金

    private String code;

    private String name;

    InterestStrategyEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }


    public static InterestStrategyEnum getByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        code = code.toUpperCase();
        return InterestStrategyMapper.map.get(code);
    }

    private static class InterestStrategyMapper {
        private static ConcurrentHashMap<String, InterestStrategyEnum> map = new ConcurrentHashMap<>();
        static {
            for (InterestStrategyEnum strategy: InterestStrategyEnum.values()) {
                map.put(strategy.code, strategy);
            }
        }
    }

}
